function [dftoYVec,deficitVec,sampVec]=deficitUpDown(NqUp,NqDown,rhoUp,rhoDown,dataEnd,dftoYInitial)
% NqUp:     Number of quarters the deficit is increasing 
% NqDown:   Number of quarters the deficit is decreasing 
% rhoUp:    Persistence on the way up 
% rhoDown:  Persistence on the way down 
% dataEnd:  Level of TB/Y to end., *from the data* without a level shift 
% dftoYInitial: Initial level of df/y quarterly 
sampVec=1998:0.25:( 1998 + ( round( NqUp+NqDown + 4 )/4) );
sampVec=sampVec(1:NqUp+NqDown); 
deficitVec=zeros(NqUp+NqDown,1); 
dftoYVec=zeros(NqUp+NqDown,1); 
levelShift=0.011; % 0.0142; 
dataBottom=-0.0589;  
%% Increase in the deficit 
%deficitVec(1:NqUp)=fliplr( linspace(dataBottom,-0.0164,NqUp) + levelShift ); 
temp=fliplr( linspace(dataBottom,-levelShift,NqUp+1) + levelShift ); 
deficitVec(1:NqUp)=temp(2:end); 
dftoYVec(1)=dftoYInitial - deficitVec(1)/(1-rhoUp); 
for ii=2:NqUp; 
   dftoYVec(ii)= dftoYVec(ii-1) - ( deficitVec(ii)-deficitVec(ii-1) )/(1-rhoUp)...
       -deficitVec(ii-1); 
end 
%% Decrease in the Deficit 
%step=deficitVec(NqUp)-deficitVec(NqUp-1); 
upVec=linspace(dataBottom,dataEnd,NqDown+1)+levelShift; 
deficitVec(NqUp+1:end)=upVec(2:end); 
   dftoYVec(ii)= dftoYVec(ii-1) - ( deficitVec(ii)-deficitVec(ii-1) )/(1-rhoDown)...
       -deficitVec(ii-1); 
for ii=NqUp+1:(NqUp+NqDown); 
   dftoYVec(ii)= dftoYVec(ii-1) - ( deficitVec(ii)-deficitVec(ii-1) )/(1-rhoDown)...
       -deficitVec(ii-1); 
end 
end 